﻿// Written by Shai Raiten: http://tinyurl.com/shai-rai
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace Fart7
{
    public partial class MainPage : PhoneApplicationPage
    {
        private MediaPlayerLauncher mediaPlayer;
        public MainPage()
        {
            InitializeComponent();
            
            mediaPlayer = new MediaPlayerLauncher();
            XmlCommands xml = new XmlCommands();

            MainList.ItemsSource = xml.GetFarts();
        }

        private void btn_fart_Click(object sender, RoutedEventArgs e)
        {
            if (MainList.SelectedItem != null)
            {
                Fart f = MainList.SelectedItem as Fart;

                mediaPlayer.Media = f.Uri;
                mediaPlayer.Controls = MediaPlaybackControls.All;
                mediaPlayer.Show();
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (NavigationService.CanGoBack)
                NavigationService.GoBack();
            else
                MessageBox.Show("Cannot navigate back... Please use the home button", "Oppss..", MessageBoxButton.OK);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/About.xaml", UriKind.Relative));
        }
    }
}
